package com.itheima.advantagesup.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.advantagesup.common.PageBean;
import com.itheima.advantagesup.dto.AdvImgCreateDTO;
import com.itheima.advantagesup.dto.AdvImgPageDTO;
import com.itheima.advantagesup.dto.AdvImgUpdateDTO;
import com.itheima.advantagesup.entity.YddAdvimg;
import com.itheima.advantagesup.entity.YddAdvpos;
import com.itheima.advantagesup.mapper.yddAdvimgMapper;
import com.itheima.advantagesup.service.yddAdvimgService;
import org.apache.logging.log4j.status.StatusConsoleListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class yddAdvimgServiceImpl implements yddAdvimgService {

    @Autowired
    private yddAdvimgMapper yddAdvimgMapper;

    @Override
    public void create(AdvImgCreateDTO advImgCreateDTO) {

        AdvImgCreateDTO advImgCreateDTO1 = new AdvImgCreateDTO();
        BeanUtils.copyProperties(advImgCreateDTO,advImgCreateDTO1);
        yddAdvimgMapper.caeate(advImgCreateDTO);
    }

    @Override
    public void deleteById(Integer id) {
        yddAdvimgMapper.deleteById(id);
    }

    @Override
    public AdvImgCreateDTO rowInfoById(String id) {
        return yddAdvimgMapper.select(id);
    }

    @Override
    public PageBean<YddAdvimg> page(AdvImgPageDTO advImgPageDTO) {
        PageHelper.startPage(advImgPageDTO.getPage(),advImgPageDTO.getLimit());
        YddAdvimg yddAdvimg = new YddAdvimg();
        BeanUtils.copyProperties(advImgPageDTO,yddAdvimg);
        Page<YddAdvimg> yddAdvimgPage=yddAdvimgMapper.selectPage(yddAdvimg);
        PageBean<YddAdvimg> pageBean = new PageBean<>();
        pageBean.setCount((int)yddAdvimgPage.getTotal());
        pageBean.setTotalPages(yddAdvimgPage.getPages());
        pageBean.setPageSize(yddAdvimgPage.getPageSize());
        pageBean.setCurrentPage(yddAdvimgPage.getPageNum());
        pageBean.setData(yddAdvimgPage.getResult());
        return pageBean;
    }

    @Override
    public void updateById(AdvImgUpdateDTO advImgUpdateDTO) {
        YddAdvimg yddAdvimg = new YddAdvimg();
        BeanUtils.copyProperties(advImgUpdateDTO,yddAdvimg);
        yddAdvimgMapper.update(yddAdvimg);
    }

}
